import { DeleteDto, IndexDto, ShowDto } from '@libs/common/dto';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsOptional } from 'class-validator';

import { DeviceResult, OrderResult } from '@/constant.enum';

import { DeviceExchangeLog } from '../entities/device-exchange-log.entity';

export class IndexDeviceExchangeLogDto extends IndexDto<DeviceExchangeLog> {}

export class ShowDeviceExchangeLogDto extends ShowDto {}

export class DeleteDeviceExchangeLogDto extends DeleteDto {}

export class CreateDeviceExchangeLogDto {
  @ApiProperty({ description: '兑换用户ID' })
  @IsNotEmpty({ message: '兑换用户ID不能为空' })
  userId: string;

  @ApiProperty({ description: '兑换用户名称' })
  @IsNotEmpty({ message: '兑换用户名称不能为空' })
  userName: string;

  @ApiProperty({ description: '商品ID' })
  @IsNotEmpty({ message: '商品ID不能为空' })
  productId: string;

  @ApiProperty({ description: '商品名称' })
  @IsNotEmpty({ message: '商品名称不能为空' })
  productName: string;

  @ApiProperty({ description: '商品价格' })
  @IsNotEmpty({ message: '商品价格不能为空' })
  productPrice: number;

  @ApiProperty({ description: '商品数量' })
  @IsNotEmpty({ message: '商品数量不能为空' })
  productNumber: number;

  @ApiProperty({ description: '订单编号' })
  @IsOptional()
  orderNo: string;

  @ApiProperty({ description: '订单状态: 0-待出货，1-成功，2-退款，-1-失败' })
  @IsOptional()
  orderStatus: OrderResult;

  @ApiProperty({ description: '流水号' })
  @IsNotEmpty({ message: '流水号不能为空' })
  deviceTransNo: string;

  @ApiProperty({ description: '货道ID' })
  @IsNotEmpty({ message: '货道ID不能为空' })
  deviceRoadId: string;

  @ApiProperty({ description: '货道号' })
  @IsNotEmpty({ message: '货道号不能为空' })
  deviceRoadNo: string;

  @ApiProperty({ description: '出货结果: 0-待出货，1-成功，-1-失败' })
  @IsEnum(DeviceResult, {
    message: '出货结果不正确',
  })
  @IsNotEmpty({ message: '出货结果不能为空' })
  deviceResult: (typeof DeviceResult)[number];
}

export class UpdateDeviceExchangeLogDto extends PartialType(
  CreateDeviceExchangeLogDto,
) {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;
}

export class SwitchDeviceExchangeLogDto {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;
}

export class ImportDeviceExchangeLogDto {}

export class ExportDeviceExchangeLogDto {}

export class DeviceExchangeEventOption {
  userId: string;
  userName: string;
  orderStatus: OrderResult;
  orderNo: string;
  productId: string;
  productName: string;
  productPrice: number;
  productNumber: number;
  deviceTransNo: string;
  deviceRoadId: string;
  deviceRoadNo: string;
  deviceResult: (typeof DeviceResult)[number];
}
